/**
  ******************************************************************************
  * @file    Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c 
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main Interrupt Service Routines.
  *          This file provides template for all exceptions handler and 
  *          peripherals interrupt service routine.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
#include "stm32f10x.h"
#include "bsp.h"
#include "stdio.h"
#include "bsp_clock.h"
// #include "sensor.h"




/** @addtogroup STM32F10x_StdPeriph_Template
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M3 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
	printf("NMI_Handler.\n\r");
	while(1)
	{
	}
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
*/
void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  printf("HardFault_Handler.\n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles Memory Manage exception.
  * @param  None
  * @retval None
  */
void MemManage_Handler(void)
{
  /* Go to infinite loop when Memory Manage exception occurs */
  printf("MemManage_Handler.\n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles Bus Fault exception.
  * @param  None
  * @retval None
  */
void BusFault_Handler(void)
{
  /* Go to infinite loop when Bus Fault exception occurs */
  printf("BusFault_Handler.\n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles Usage Fault exception.
  * @param  None
  * @retval None
  */
void UsageFault_Handler(void)
{
  /* Go to infinite loop when Usage Fault exception occurs */
  printf("UsageFault_Handler.\n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
  printf("SVC_Handler.\n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles Debug Monitor exception.
  * @param  None
  * @retval None
  */
void DebugMon_Handler(void)
{
  printf("DebugMon_Handler.\n\r");
  while (1)
  {
  }
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
/*
void PendSV_Handler(void)
{
}
*/
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
  // static int32_t SystickCount	  = 0;
  // static int32_t SystickCountRev   = 0;
  // static int32_t SystickDelayCount = 0;

	// ++SystickCount;
	// if(0 == SystickCount){
	// 	++SystickCountRev;
	// }
	// if(0 < SystickDelayCount){
	// 	--SystickDelayCount;
	// }
	SysClock_Step();

}




/******************************************************************************/
/*                 STM32F10x Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (startup_stm32f10x_xx.s).                                            */
/******************************************************************************/

/**
  * @brief  This function handles PPP interrupt request.
  * @param  None
  * @retval None
  */
/*void PPP_IRQHandler(void)
{
}*/

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
*/
void WWDG_IRQHandler(void)
{
  printf("WWDG_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : PVD_IRQHandler
* Description   : This function handles PVD interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void PVD_IRQHandler(void)
{
  printf("PVD_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : TAMPER_IRQHandler
* Description   : TThis function handles Tamper interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void TAMPER_IRQHandler(void)
{
  printf("TAMPER_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : RTC_IRQHandler
* Description   : This function handles RTC global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void RTC_IRQHandler(void)
{
  printf("RTC_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : FLASH_IRQHandler
* Description   : This function handles Flash interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void FLASH_IRQHandler(void)
{
  printf("FLASH_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : RCC_IRQHandler
* Description   : This function handles RCC interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void RCC_IRQHandler(void)
{
  printf("RCC_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : EXTI0_IRQHandler
* Description   : This function handles External interrupt Line 0 request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void EXTI0_IRQHandler(void)
{
  printf("EXTI0_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : EXTI1_IRQHandler
* Description   : This function handles External interrupt Line 1 request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void EXTI1_IRQHandler(void)
{
  printf("EXTI1_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : EXTI2_IRQHandler
* Description   : This function handles External interrupt Line 2 request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void EXTI2_IRQHandler(void)
{
  printf("EXTI2_IRQHandler.\n\r");
  while (1)
  {
  }
}
/*******************************************************************************
* Function Name : EXTI3_IRQHandler
* Description   : This function handles External interrupt Line 3 request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void EXTI3_IRQHandler(void)
{
  printf("EXTI3_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : EXTI4_IRQHandler
* Description   : This function handles External interrupt Line 4 request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void EXTI4_IRQHandler(void)
{
  printf("EXTI4_IRQHandler.\n\r");
  while (1)
  {
  }
}
/*******************************************************************************
* Function Name : DMAChannel1_IRQHandler
* Description   : This function handles DMA Stream 1 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel1_IRQHandler(void)
{
  printf("DMA1_Channel1_IRQHandler.\n\r");
  while (1)
  {
  }	 
}

/*******************************************************************************
* Function Name : DMAChannel2_IRQHandler
* Description   : This function handles DMA Stream 2 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel2_IRQHandler(void)
{
  printf("DMA1_Channel2_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : DMAChannel3_IRQHandler
* Description   : This function handles DMA Stream 3 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel3_IRQHandler(void)
{
  printf("DMA1_Channel3_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : DMAChannel4_IRQHandler
* Description   : This function handles DMA Stream 4 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel4_IRQHandler(void)
{
  printf("DMA1_Channel4_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : DMAChannel5_IRQHandler
* Description   : This function handles DMA Stream 5 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel5_IRQHandler(void)
{
  printf("DMA1_Channel5_IRQHandler.\n\r");
  while (1)
  {
  }
}
/*******************************************************************************
* Function Name : DMAChannel6_IRQHandler
* Description   : This function handles DMA Stream 6 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel6_IRQHandler(void)
{
  printf("DMA1_Channel6_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : DMAChannel7_IRQHandler
* Description   : This function handles DMA Stream 7 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void DMA1_Channel7_IRQHandler(void)
{
  printf("DMA1_Channel7_IRQHandler.\n\r");
  while (1)
  {
  }	
}

/*******************************************************************************
* Function Name : ADC_IRQHandler
* Description   : This function handles ADC global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void ADC_IRQHandler(void)
{
  printf("ADC_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : USB_HP_CAN_TX_IRQHandler
* Description   : This function handles USB High Priority or CAN TX interrupts 
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void USB_HP_CAN1_TX_IRQHandler(void)
{
  printf("USB_HP_CAN1_TX_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : USB_LP_CAN_RX0_IRQHandler
* Description   : This function handles USB Low Priority or CAN RX0 interrupts 
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
//void USB_LP_CAN1_RX0_IRQHandler(void)
//{
//  printf("USB_LP_CAN1_RX0_IRQHandler.\n\r");
//  while (1)
//  {
//  }
//}

/*******************************************************************************
* Function Name : CAN_RX1_IRQHandler
* Description   : This function handles CAN RX1 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void CAN1_RX1_IRQHandler(void)
{
  printf("CAN1_RX1_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : CAN_SCE_IRQHandler
* Description   : This function handles CAN SCE interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void CAN1_SCE_IRQHandler(void)
{
  printf("CAN1_SCE_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : EXTI9_5_IRQHandler
* Description   : This function handles External lines 9 to 5 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/

void EXTI9_5_IRQHandler(void)
{
  printf("EXTI9_5_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : TIM1_BRK_IRQHandler
* Description   : This function handles TIM1 Break interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void TIM1_BRK_IRQHandler(void)
{
  printf("TIM1_BRK_IRQHandler.\n\r");
  while (1)
  {
  }
}
/*******************************************************************************
* Function Name : TIM1_UP_IRQHandler
* Description   : This function handles TIM1 overflow and update interrupt
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void TIM1_UP_IRQHandler(void)
{
  printf("TIM1_UP_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : TIM1_TRG_COM_IRQHandler
* Description   : This function handles TIM1 Trigger and Commutation interrupts 
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void TIM1_TRG_COM_IRQHandler(void)
{
  printf("TIM1_TRG_COM_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : TIM1_CC_IRQHandler
* Description   : This function handles TIM1 capture compare interrupt request. 
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void TIM1_CC_IRQHandler(void)
{
  printf("TIM1_CC_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : TIM2_IRQHandler 
* Description   : This function handles TIM2 global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/

void TIM2_IRQHandler(void)
{
  	//  	printf("TIM2_IRQHandler[%d].\n\r", zbc++);
  if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
#if UART1_FIFO_EN == 1 		
    UartOverTime(&g_tUart1);  
#endif
#if UART2_FIFO_EN == 1      
    UartOverTime(&g_tUart2);
#endif		
		
	}
}

/*******************************************************************************
* Function Name : TIM3_IRQHandler 
* Description   : This function handles TIM3 global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/

void TIM3_IRQHandler(void)
{
  printf("TIM3_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : TIM4_IRQHandler
* Description   : This function handles TIM4 global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/

void TIM4_IRQHandler(void)
{
  printf("TIM4_IRQHandler\n\r");
  while (1)
  {
  }
}


/**
  * @brief  This function handles CAN1 RX0 request.
  * @param  None
  * @retval None
  */
void USB_LP_CAN1_RX0_IRQHandler(void)
{
	CAN_IRQ();
}
/*******************************************************************************
* Function Name : I2C1_EV_IRQHandler
* Description   : This function handles I2C1 Event interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void I2C1_EV_IRQHandler(void)
{
  printf("I2C1_EV_IRQHandler.\n\r");
  while (1)
  {
  }	
}

/*******************************************************************************
* Function Name : I2C1_ER_IRQHandler
* Description   : This function handles I2C1 Error interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void I2C1_ER_IRQHandler(void)
{
  printf("I2C1_ER_IRQHandler.\n\r");
  while (1)
  {
  }	
}

/*******************************************************************************
* Function Name : I2C2_EV_IRQHandler
* Description   : This function handles I2C2 Event interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void I2C2_EV_IRQHandler(void)
{
  printf("I2C2_EV_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : I2C2_ER_IRQHandler
* Description   : This function handles I2C2 Error interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void I2C2_ER_IRQHandler(void)
{
  printf("I2C2_ER_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : SPI1_IRQHandler
* Description   : This function handles SPI1 global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void SPI1_IRQHandler(void)
{
  printf("SPI1_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : SPI2_IRQHandler
* Description   : This function handles SPI2 global interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void SPI2_IRQHandler(void)
{
  printf("SPI2_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : USART1_IRQHandler
* Description   : This function handles USART1 global interrupt request.
* Input         : None
* Return        : None
* Created By	: LBQ 	
* Created date	: 2011.8.12
*-------------------------------------------------------------------------------
*******************************************************************************/
void USART1_IRQHandler(void)
{
  // printf("USART1_IRQHandler.\n\r");
  // while (1)
  // {
  // }	
#if UART1_FIFO_EN == 1   
  UartIRQ(&g_tUart1);
#endif
}

/*******************************************************************************
* Function Name : USART2_IRQHandler
* Description   : This function handles USART2 global interrupt request.
* Input         : None
* Return        : None
* Created By	: LBQ 	
* Created date	: 20011.8.12
*-------------------------------------------------------------------------------
*******************************************************************************/

void USART2_IRQHandler(void)
{
  // printf("USART2_IRQHandler.\n\r");
  // while (1)
  // {
  // }
#if UART2_FIFO_EN == 1  
  UartIRQ(&g_tUart2);
#endif 
}


/*******************************************************************************
* Function Name : USART3_IRQHandler
* Description   : This function handles USART3 global interrupt request.
* Input         : None
* Return        : None
* Created By	: LBQ 	
* Created date	: 2011.8.12
*-------------------------------------------------------------------------------
*******************************************************************************/

void USART3_IRQHandler(void)
{
  printf("USART3_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : UART4_IRQHandler
* Description   : This function handles USART3 global interrupt request.
* Input         : None
* Return        : None
* Created By	: LBQ 	
* Created date	: 2011.8.12
*-------------------------------------------------------------------------------
*******************************************************************************/

void UART4_IRQHandler(void)
{
  printf("USART4_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : UART5_IRQHandler
* Description   : This function handles USART3 global interrupt request.
* Input         : None
* Return        : None
* Created By	: LBQ 	
* Created date	: 2011.8.12
*-------------------------------------------------------------------------------
*******************************************************************************/

void UART5_IRQHandler(void)
{
  printf("USART5_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : EXTI15_10_IRQHandler
* Description   : This function handles External lines 15 to 10 interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void EXTI15_10_IRQHandler(void)
{
  printf("EXTI15_10_IRQHandler.\n\r");
  while (1)
  {
  }	 	
  // EXTI15_10IRQ();	
}

/*******************************************************************************
* Function Name : RTCAlarm_IRQHandler
* Description   : This function handles RTC Alarm interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void RTCAlarm_IRQHandler(void)
{
  printf("RTCAlarm_IRQHandler.\n\r");
  while (1)
  {
  }
}

/*******************************************************************************
* Function Name : USBWakeUp_IRQHandler
* Description   : This function handles USB WakeUp interrupt request.
* Input         : None
* Return        : None
* Created By	:  	
* Created date	: 
*-------------------------------------------------------------------------------
*******************************************************************************/
void USBWakeUp_IRQHandler(void)
{
  printf("USBWakeUp_IRQHandler.\n\r");
  while (1)
  {
  }
}

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
